package com.controller.admin;

import com.entity.Goods;
import com.service.admin.AdminGoodService;
import com.service.admin.AdminReportService;
import com.service.user.GoodService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
public class AdminGoodController {
  @Autowired AdminGoodService adminGoodService;
  @Autowired GoodService goodService;
  @Autowired AdminReportService adminReportService;

  /**
   * 获取所有商品数量（不包括已删除的）
   *
   * @return 商品数量
   */
  @PostMapping("admin/getAllGoodCount")
  public String getAllGoodCount() {
    int count = adminGoodService.getAllGoodCount();
    return String.valueOf(count);
  }

  /**
   * 获取所有商品
   *
   * @param pageSize 页大小
   * @param pageIndex 页索引
   * @return 商品列表
   */
  @PostMapping("admin/getAllGoods")
  public List<Goods> getAllGoods(
      @RequestParam("pageSize") int pageSize,
      @RequestParam("pageIndex") int pageIndex,
      String goodId,
      @RequestParam(value = "status", defaultValue = "1") int status,
      Float fromPrice,
      Float toPrice,
      Integer categoryId,
      String name,
      String userId,
      Date fromUpdateTime,
      Date toUpdateTime,
      Date fromPublicDate,
      Date toPublicDate,
      String author,
      String appearance,
      String pressHorse,
      String sortWay) {
    return goodService.getGoods(
        pageSize,
        pageIndex,
        goodId,
        status,
        fromPrice,
        toPrice,
        categoryId,
        name,
        userId,
        fromUpdateTime,
        toUpdateTime,
        fromPublicDate,
        toPublicDate,
        author,
        appearance,
        pressHorse,
        sortWay);
  }

  /**
   * 设置书籍不合格
   *
   * @param adminName 管理员姓名
   * @param goodId 商品编号
   * @param type 举报类型
   * @param reason 举报原因
   * @param pic1 证据截图1
   * @param pic2 证据截图2
   * @param pic3 证据截图3
   * @param result 处理结果：1为提醒，2为警告，3为终止卖书
   * @param noticeSeller 回复模板
   * @return 成功返回1，失败返回0
   */
  @PostMapping("admin/setGoodUnqualified")
  public String setGoodUnqualified(
      @RequestParam("adminName") String adminName,
      @RequestParam("goodId") String goodId,
      @RequestParam("type") String type,
      @RequestParam("reason") String reason,
      MultipartFile pic1,
      MultipartFile pic2,
      MultipartFile pic3,
      @RequestParam("result") int result,
      @RequestParam("noticeSeller") String noticeSeller) {
    int ret =
        adminReportService.setGoodUnqualified(
            adminName, goodId, type, reason, pic1, pic2, pic3, result, noticeSeller);
    return String.valueOf(ret);
  }
}
